package com.pdg.mcplugin.common.deprecated;

import com.pdg.mcplugin.common.baseclasses.DataProviderBase;
import com.pdg.mcplugin.common.baseclasses.PluginBase;
import com.pdg.mcplugin.common.baseclasses.PluginClientBase;

public abstract class DeprecatedTableProviderBase<E extends PluginBase,K,V> extends PluginClientBase<E> implements DeprecatedTableProvider<K,V>{

	private DataProviderBase<E> dataProvider;
	private String tableName;
	
	public DeprecatedTableProviderBase(DataProviderBase<E> theDataProvider,String theTableName) {
		super(theDataProvider.getPlugin());
		setDataProvider(theDataProvider);
		setTableName(theTableName);
	}

	private void setTableName(String theTableName) {
		tableName = theTableName;
	}
	
	protected String getTableName(){
		return tableName;
	}

	private void setDataProvider(DataProviderBase<E> theDataProvider) {
		dataProvider = theDataProvider;
	}
	
	protected DataProviderBase<E> getDataProvider(){
		return dataProvider;
	}
	
	protected abstract void ensureTableExists();
	
	protected abstract boolean createEntry(K theKey, V theValue);
	
	protected abstract V retrieveEntry(K theKey);
	
	protected abstract boolean updateEntry(K theKey,V theValue);
	
	protected abstract boolean deleteEntry(K theKey);
	
	protected abstract boolean entryExists(K theKey);
	
	public boolean create(K theKey, V theValue){
		ensureTableExists();
		return createEntry(theKey,theValue);
	}
	public boolean exists(K theKey){
		ensureTableExists();
		return entryExists(theKey);
	}
	public V retrieve(K theKey){
		ensureTableExists();
		return retrieveEntry(theKey);
	}
	public boolean update(K theKey, V theValue){
		ensureTableExists();
		return updateEntry(theKey,theValue);
	}
	public boolean delete(K theKey){
		ensureTableExists();
		return deleteEntry(theKey);
	}
	
}
